package com.cloud.school.app.util.mapstruct;

import com.google.common.collect.Lists;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @ClassName IBaseConvertUtil
 * @Description TODO
 * @Author 36297
 * @Date 2018/12/30 18:27
 * @Version 1.0
 */
@Component
public class IBaseConvertUtil {
    public String asString(Long value) {
        return value == null ? null : value.toString();

    }

    public Long asLong(String value) {
        return value == null ? 0l : Long.parseLong(value);
    }

    public String asString(List<Long> value) {
        return value == null || value.size() == 0 ? null : String.join(",", value.stream().filter(v -> v != null).map(v -> v.toString()).collect(Collectors.toList()));
    }

    public List<Long> asList(String value) {
        return StringUtils.isEmpty(value) ? Lists.newArrayList() : Stream.of(value.split(",")).filter(v -> !"".equals(v)).map(v -> Long.parseLong(v)).collect(Collectors.toList());
    }
}
